package edu.gatech.volt2.drdoommgt.domain;
import java.util.Calendar;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.OneToMany;
import javax.persistence.CascadeType;


import javax.persistence.GeneratedValue;
import org.hibernate.annotations.GenericGenerator;


/**
 * This class represents the information of a patient
 * 
 * @author Perron Jones
 */

@Entity
@Table(name="patients_info")
public class PatientInfo 
{
	@Id
	@GeneratedValue(generator="increment")
	@GenericGenerator(name="increment", strategy = "increment")
	private long id;
	private String gender;
	private Calendar birthday;
	private Address address;
	private String phone;
	@Transient
	private MedicalInfo medInfo;
	@OneToMany(cascade = {CascadeType.ALL})
	private List<TreatmentRecord> medHistory;
	
	/**
	 * This default constructor sets the metadata of the patient information to
	 * customized default values.
	 */
	public PatientInfo()
	{
		this.gender= null;
		this.birthday= null;
		this.medHistory= new ArrayList<TreatmentRecord>();
		this.phone= null;
		this.address= new Address();
		this.medInfo= new MedicalInfo();
	}
	
	/**
	 * This constructor sets the metadata of the patient information to the information
	 * that is passed into it.
	 * 
	 * @param gender the gender (male or female) of the patient
	 * @param birthday the birthday of the patient
	 * @param medHistory the medical history of the patient (a list of treatment records)
	 * @param contactInformation the contact information of the patient
	 * @param address the address of the patient
	 * @param medInfo the medical information of the patient
	 */
	public PatientInfo(String gender, Calendar birthday, List<TreatmentRecord> medHistory, String phone,
				Address address, MedicalInfo medInfo)
	{
		this.gender= (gender == null ? "N/A" : gender);
		this.birthday= (birthday == null ? Calendar.getInstance() : birthday);
		this.medHistory= (medHistory == null ? new ArrayList<TreatmentRecord>() : medHistory);
		this.phone= (phone == null ? "" : phone);
		this.address= (address == null ? new Address() : address);
		this.medInfo= (medInfo == null ? new MedicalInfo() : medInfo);
	}
	
	public PatientInfo(Patient patient) {
		// Generate from database
		// SELECT * FROM `patient_info` WHERE `patient_id` = patient.id;
	}

	/**
	 * This method creates a string representation of the patient's information
	 * 
	 * @return a string representation of the patient's information
	 */
	public String toString()
	{
		String bday= this.birthday.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH) +
		" " + Integer.toString(this.birthday.get(Calendar.DAY_OF_MONTH)) +
		", " + Integer.toString(this.birthday.get(Calendar.YEAR));
		String info = "Gender: " + this.gender + "\nBirthday: " + bday + "\nPhone number:\n" + this.phone +
			"\nAddress:\n" + this.address.toString() + "\nMedical Information:\n" + this.medInfo.toString();
		
		return info;
	}
	
	
	/**
	 * @param gender the gender of the patient (male of female) to set
	 */
	public void setGender(String gender)
	{
		this.gender = gender;
	}
	
	/**
	 * @return the gender of the patient (male or female)
	 */
	public String getGender()
	{
		return gender;
	}
	
	/**
	 * @param birthday the birthday of the patient to set
	 */
	public void setBirthday(Calendar birthday)
	{
		this.birthday = birthday;
	}
	
	/**
	 * @return the birthday of the patient
	 */
	public Calendar getBirthday()
	{
		return birthday;
	}
	
	/**
	 * @param medHistory the medical history(list of treatment records) of the patient to set
	 */
	public void setMedHistory(ArrayList<TreatmentRecord> medHistory)
	{
		this.medHistory = medHistory;
	}
	
	/**
	 * @return the medical history (list of treatment records) of the patient
	 */
	public List<TreatmentRecord> getMedHistory()
	{
		return medHistory;
	}
		
	/**
	 * @param address the address of the patient to set
	 */
	public void setAddress(Address address)
	{
		this.address = address;
	}
	
	/**
	 * @return the address of the patientS
	 */
	public Address getAddress()
	{
		return address;
	}
	
	/**
	 * @return the phone
	 */
	public String getPhone() {
		return phone;
	}

	/**
	 * @param phone the phone to set
	 */
	public void setPhone(String phone) {
		this.phone = phone;
	}

	/**
	 * @param medInfo the medical information of the patient to set
	 */
	public void setMedInfo(MedicalInfo medInfo)
	{
		this.medInfo = medInfo;
	}
	
	/**
	 * @return the medical information of the patient
	 */
	public MedicalInfo getMedInfo()
	{
		return medInfo;
	}
}
